﻿using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace TeacherLeftHand.DocEditor
{
    public class BoolToVisibilityConverter : IValueConverter
    {
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            // Only convert to brushes...
            if (targetType != typeof(Visibility))
            {
                return null;
            }
            // DANGER! After 25, it's all downhill...
            var check = value.GetType() == typeof(bool) ? (bool) value: value.ToString().Equals("True");
            
            return check ? Visibility.Visible : Visibility.Collapsed;
        }

        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            if (targetType != typeof(bool))
            {
                return null;
            };
            var visible = value.ToString().Equals("Visible");
            return visible ? true : false;
        }
    }
}